import { idCardOCR, verify } from '../../../util/idCard/index';

// 身份证识别
export async function ocrCard(ctx: Context, next: Next): Promise<void> {
  const { imgUrl } = ctx.request.body;

  try {
    const result = await idCardOCR(imgUrl);
    ctx.api.success(result, 'sucess');
  } catch (error) {
    ctx.api.fail(-1, error);
  }
  
  return next();
}

// 身份证认证
export async function verifyIdCard(ctx: Context, next: Next): Promise<void> {
  const { idCard, name } = ctx.request.body;

  try {
    const result = await verify({ idCard, name });
    ctx.api.success(result, 'sucess');
  } catch (error) {
    ctx.api.fail(-1, error);
  }
  
  return next();
}